<!DOCTYPE html>
<html>

	<head>
		<!-- 声明文档使用的字符编码 -->
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
		<!-- 为移动设备添加 viewport -->
		<meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no">
		<!-- 针对手持设备优化，主要是针对一些老的不识别viewport的浏览器，比如黑莓 -->
		<meta name="HandheldFriendly" content="true">
		<!-- 优先使用 IE 最新版本和 Chrome -->
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">

		<title>黑图视界</title>
		<meta name="keywords" content="黑图视界">
		<meta name="description" content="黑图视界">
		<script type="text/javascript" src="../js/setFontSize.js"></script>
		<script type="text/javascript" src="../js/layui/layui.js" ></script>
		<link rel="stylesheet" href="../js/layui/css/layui.css" media="all">
		<link rel="stylesheet" href="../css/swiper.min.css" />
		<link rel="stylesheet" href="../css/main.css" />
	</head>

	<body>
		<main id="app">
			<section class="profileItem whiteBg mbt30">
				<div class="container">
					<h3 class="commonTitle"><i class="icon"></i>票信息</h3>
					<h3 class="commonTitle">票名:  <input type="text" v-model="activityAndRule.activity.activityname" style="border: black 1px solid"></h3>
					<h3 class="commonTitle"><i class="icon"></i>发布规则</h3>
					<h3 class="commonTitle">最大提前预约时间:  <input type="text" v-model="activityAndRule.rule.beforeday" style="border: black 1px solid;width: 50px">天</h3>
					<h3 class="commonTitle">每天可预约次数:  <input type="text" v-model="activityAndRule.rule.ticketnum" style="border: black 1px solid;width: 50px">次</h3>
					<h3 class="commonTitle">周末是否可预约:
						<select v-model="activityAndRule.rule.weekendcanbook">
							<option value="true">是</option>
							<option value="false">否</option>
						</select>
					</h3>
					<h3 class="commonTitle">节假日是否可预约:
						<select v-model="activityAndRule.rule.holidaycanbook">
							<option value="true">是</option>
							<option value="false">否</option>
						</select>
					</h3>
					<h3 class="commonTitle">开始时间:  <input type="datetime-local" step="1" v-model="activityAndRule.rule.starttime"></h3>
					<h3 class="commonTitle">结束时间:  <input type="datetime-local" step="1" v-model="activityAndRule.rule.endtime"></h3>
				</div>
				<div class="asideBox">
					<div class="container">
						<a class="asideBtn" @click="submit">提交</a>
					</div>
				</div>
			</section>
		</main>
		<script type="text/javascript" src="../js/jquery-3.3.1.min.js"></script>
		<script type="text/javascript" src="../js/swiper.min.js"></script>
		<script type="text/javascript" src="../js/layer/layer.js" ></script>
		<script type="text/javascript" src="../js/main.js"></script>
		<script src="../js/axios.js"></script>
		<script src="../js/vue.js"></script>
		<script src="../js/getParameter.js"></script>
		<script>
			let aid = getParameter("aid");
			if (aid===null) location.href = "myActivityList.html"
			const app=new Vue({
				el:"#app",
				data:{
					activityAndRule:{}
				},
				methods:{
					loadActivityDetail(){
						axios.get("/activity/detail/"+aid).then(function (res) {
							if (res.data===""){
								location.href = "/managerclient/myActivityList.html"
								layer.msg("查询错误")
							}
							app.activityAndRule = res.data
						})
					},
					submit(){
						app.activityAndRule.rule.starttime = app.activityAndRule.rule.starttime.replace("T"," ")
						app.activityAndRule.rule.endtime = app.activityAndRule.rule.endtime.replace("T"," ")
						let timeReg = /:[0-9]{2}:/
						if (!timeReg.test(app.activityAndRule.rule.starttime)) app.activityAndRule.rule.starttime+=":00"
						if (!timeReg.test(app.activityAndRule.rule.endtime)) app.activityAndRule.rule.endtime+=":00"
						let priceReg = /^[0-9]{1,}$/
						// if(this.activityAndRule.activity.effectivetime==="") layer.msg("有效期不能为空")
						// else if (!priceReg.test(this.activityAndRule.activity.effectivetime)) layer.msg("有效期只能输入数字")
						if(this.activityAndRule.rule.beforeday==="") layer.msg("最大提前预约时间不能为空")
						else if (!priceReg.test(this.activityAndRule.rule.beforeday)) layer.msg("最大提前预约时间只能输入数字")
						else if(this.activityAndRule.rule.ticketnum==="") layer.msg("每天预约次数不能为空")
						else if (!priceReg.test(this.activityAndRule.rule.ticketnum)) layer.msg("每天预约次数只能输入数字")
						else {
							axios.post("/activity/update",{
								activityAndRule:app.activityAndRule
							}).then(function (res) {
								if (res.data==="success"){
									layer.msg("修改成功")
									app.loadActivityDetail()
								}else{
									layer.msg(res.data)
								}
							})
						}
					}
				},
				created(){
					this.loadActivityDetail()
				}
			})
		</script>

	</body>

</html>